package org.itboys.trade.service;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.itboys.trade.entity.PrePay;
import org.mongodb.morphia.mapping.Mapper;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


@Service
public class PrePayService extends BaseService<PrePay, Long>{

	private static final long serialVersionUID = 1L;
	
	@Resource(name = "orderDS")
	private MongoDataSource ds;
	
	@Override
	protected MongoDataSource getMongoDataSource() {
		return ds;
	}
	@Override
	protected Class<PrePay> getEntityClass() {
		return PrePay.class;
	}

    public List<PrePay> getPaysByOrderIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.emptyList();
        }
        return ds.createQuery(getEntityClass())
                .field("status").equal(PrePay.status_success)
                .field("orderId").in(ids).asList();
    }
}
